package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CheckgroupMapper extends BaseMapper<CheckGroup> {

    @Insert("insert into t_checkgroup_checkitem values(#{groupId},#{itemId})")
    public void addCheckgroupWithCHeckitem(@Param("groupId")int groupId,@Param("itemId") int itemId);

    @Select("select CHECKITEM_ID from t_checkgroup_checkitem where CHECKGROUP_ID = #{groupId}")
    public List<Integer> findCheckitemIds(Integer groupId);

    @Delete("delete from t_checkgroup_checkitem where CHECKGROUP_ID = #{groupId}")
    public void deleteCheckitemsByGroupId(Integer groupId);

    @Select("select count(1) FROM t_checkgroup where (name LIKE concat('%',#{queryString},'%') OR HELPCODE LIKE concat('%',#{queryString},'%')) AND is_delete = 0")
    public Integer findCount(String queryString);

    @Select("SELECT * FROM t_checkgroup WHERE (name LIKE concat('%',#{queryString},'%') OR HELPCODE LIKE concat('%',#{queryString},'%')) AND is_delete = 0 LIMIT #{start},#{pageSize}")
    public List<CheckGroup> findGroups(@Param("queryString")String queryString,@Param("start")Integer start,@Param("pageSize")Integer pageSize);

    @Select("select tc.name from t_checkgroup_checkitem tcgc,t_checkitem tc" +
            " where tcgc.checkitem_id = tc.id" +
            " and tcgc.checkgroup_id = #{id}" +
            " and tc.is_delete = 0")
    public List<CheckItem> findCheckItemByCheckgroupId(Integer id);
}
